-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support windows command resolution #1290
Conversation
Thanks for the pull request! Here is what will happen next:
Thank you for contributing! |
if current_candidate.is_file() { | ||
return Some(current_candidate); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like in Ruby, the last line of a function is the return value in Rust. Short-circuiting the function with return Some(T)
on 228 is great, but we should fall through to a None below this line. That would allow you to remove the ;
on 233 & the explicit call to return None
on 232.
These are small suggestions but they'll make the function control flow read a bit easier and be more "rust-like"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely appreciate the feedback on making it more rust-like!
@@ -201,13 +201,39 @@ pub fn find_command(command: &str) -> Option<PathBuf> { | |||
if candidate.is_file() { | |||
return Some(candidate); | |||
} | |||
else { | |||
match find_command_with_pathext(&candidate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The match here would be unnecessary if the ;
on line 202 was removed along with the None
on line 211. find_command_with_pathext
already returns an Option
so if you just call that without the ;
appended to the end you'll get the return value you're looking for!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback!
I think that would only work for the first path in the path variable checked. The second part of the match None => {}
is what lets things proceed on to the next path to check.
I'm going to write some tests to validate the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, you're right. I looked quick and didn't notice we were in an iterator and trying to short-circuit out of it in this function as well
1c2a421
to
2ab1c98
Compare
Signed-off-by: Steven Murawski <steven.murawski@gmail.com>
Signed-off-by: Steven Murawski <steven.murawski@gmail.com>
093fab6
to
d032ac1
Compare
@reset I've made some changes to the structure and behavior and added a bunch of tests. Mind giving it another 👀 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just the one comment to address regarding the debug output
@@ -199,7 +241,13 @@ pub fn find_command(command: &str) -> Option<PathBuf> { | |||
for path in env::split_paths(&paths) { | |||
let candidate = PathBuf::from(&path).join(command); | |||
if candidate.is_file() { | |||
println!("Found {:?}", candidate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's either debug output or something left over from iterating. If it's debug output let's use debug!()
instead of println!()
and if it's just left over from iterating remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thought I killed all those. I'll remove it.
} | ||
} | ||
|
||
#[cfg(target_os="windows")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a neat way to group tests in a platform dependent way. I hadn't seen us use submodules in a test module yet but this is a nice pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started using the modules as a way to group the tests to keep the function names shorter, but it became handy when I needed to make one windows only :)
Signed-off-by: Steven Murawski <steven.murawski@gmail.com>
d032ac1
to
82af3ad
Compare
@thesentinels approve |
🤘 I am testing your branch against master before merging it. We do this to ensure that the master branch is never failing tests. |
Travis CI has started testing this PR. |
💖 Travis CI reports this PR passed. It always makes me feel nice when humans approve of one anothers work. I'm merging this PR now. I just want you and the contributor to answer me one question: |
progress on #1192 |
Adds search by PATHEXT extensions to the command search of PATH.
Signed-off-by: Steven Murawski steven.murawski@gmail.com